package com.CMS.client.ui.view;

import com.CMS.client.datasource.MenuDataSource;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;

public class MenuView extends BaseABMView{

	private static final String DESCRIPTION = "MenuView";
	private ListGrid grid = new ListGrid();
	
	public MenuView(){
		super();
		grid.setDataSource(new MenuDataSource());
		grid.setAutoFetchData(true);  
	    grid.setCanEdit(true);  
	    grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
	    grid.setDataPageSize(20);
	    grid.invalidateCache();
	    grid.draw();
		this.addMember(grid);
	}
	
	@Override
	public void setNew() {
		grid.startEditingNew();
	}

	@Override
	public void setAccept() {
		grid.updateData(grid.getSelectedRecord());
	}

	@Override
	public void setCancel() {
		grid.cancelEditing();
	}

	@Override
	public void setDelete() {
		grid.removeSelectedData();
		grid.fetchData();
	}

	@Override
	public void setRefersh() {
		grid.fetchData();
	}
	
	public static class Factory implements ContextAreaFactory
	 {
		 private String id;
		 
		 public Canvas create()
		 {
	      //hay que crear la vista que vamos a llamar
		  MenuView view = new MenuView();
		  id = view.getID();
	      return view;
	     }
		 
		 public String getID()
		 {
		   return id;
		 }

		 public String getDescription() 
		 {
		   return DESCRIPTION;
		 }
	 }

}
